import qiniu

access_key = "oHY83bItU0ogWNc3Xj11wL6SsitdGvh9ckPYMEaY"
secret_key = "DG9t26svG5blU8JxxGo9ajZR6JCCp-v7lLHFHEWA"
bucket_name = "ihome"

def storage(data):
    try:
        q = qiniu.Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        ret, info = qiniu.put_data(token, None, data)
    except Exception as e:
        raise e

    if info.status_code != 200:
        raise Exception("上传图片失败")

    return ret["key"]

if __name__ == '__main__':
    file = input("请输入文件路径")
    with open(file, "rb") as f:
        storage(f.read())